#pragma once
#pragma warning(disable : 4244)
#pragma warning(disable : 26451)

#include "../QBase.h"

#include <gdiplus.h>
#include <math.h>
#include <istream>

#pragma comment(lib, "gdiplus.lib")
#pragma comment(lib, "MSIMG32.LIB")

#define QShapeSetHighQuality(object) object.SetSmoothingMode(Gdiplus::SmoothingMode::SmoothingModeHighQuality)

QNamespaceStart(Qui)

void QGetimage(int x, int y, int width, int height, 
	IMAGE* image_get);
void QPutimage(int x, int y, IMAGE* image_beput,
	int transparency = 255, IMAGE* target = NULL);

HDC  QGetImageHDC(IMAGE* image);

void QLoadImage(IMAGE* image, LPCTSTR image_path, int width = 0, int height = 0,
					bool resize = false);
void QLoadImage(IMAGE* image, LPCTSTR resouce_type, LPCTSTR source_name, int width = 0, int height = 0,
					bool resize = false);

void QRenderimageAlpha(IMAGE* image);

// For Anti-aliasing Qui write a new draw function

// GDI startup and shutdown class
class _QShapeServer
{
	private:
		Gdiplus::GdiplusStartupInput gdi_startup_input;
		ULONG_PTR					 gdi_token;

	private:
		HDC                          default_hdc;

	public:
		_QShapeServer()
		{
			default_hdc = GetImageHDC(NULL);
			Gdiplus::GdiplusStartup(&gdi_token, &gdi_startup_input, NULL);
		}
		~_QShapeServer()
		{
			Gdiplus::GdiplusShutdown(gdi_token);
		}

		void load_hdc()
		{
			default_hdc = GetImageHDC(NULL);
		}

		HDC get_window_hdc()
		{
			return default_hdc;
		}
};

extern _QShapeServer __Shape_server_class;

void QDrawEllipse(int x1, int y1, int x2, int y2,
					IMAGE* result_image = nullptr);
void QDrawRectangle(int x1, int y1, int x2, int y2,
					IMAGE* result_image = nullptr);
void QDrawPolygon(int x, int y, const POINT* points, int point_number);

void QDrawFillEllipse(int x1, int y1, int x2, int y2,
					IMAGE* result_image = nullptr);
void QDrawFillRectangle(int x1, int y1, int x2, int y2,
					IMAGE* result_image = nullptr);
void QDrawFillPolygon(int x, int y, const POINT* points, int point_number,
					IMAGE* result_image = nullptr);

void QDrawSoildEllipse(int x1, int y1, int x2, int y2,
					IMAGE* result_image = nullptr);
void QDrawSoildRectangle(int x1, int y1, int x2, int y2,
					IMAGE* result_image = nullptr);
void QDrawSoildPolygon(int x, int y, POINT* points, int point_number,
					IMAGE* result_image = nullptr);

void QOutTextXy(int x, int y, LPCTSTR string);
void QOutTextCenter(IMAGE* canvas, LPCTSTR string, bool focus = false);
int  QTextWidth(LPCTSTR string);
int  QTextHeight(LPCTSTR string);

void QDrawShadow(Gdiplus::Graphics& graphics, Gdiplus::GraphicsPath& path, int shadow_pixel);

void QResizeImage(IMAGE* image, int width, int height);

QNamespaceEnd